package dao;

import common.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class ChangeInfo {
    private static Connection conn=DataBaseConnect.getConn();
    private static String sql="update account set name=?,birthdate=?,phone=? where id=?";
    private static PreparedStatement pstmt;
    static {
        try {
            pstmt=conn.prepareStatement(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public static void infoChange(User user){
        try {
            pstmt.setString(1, user.getName());
            pstmt.setString(2,user.getBirth());
            pstmt.setString(3,user.getPhone());
            pstmt.setString(4,user.getId());
            int count=pstmt.executeUpdate();
            if(count==1){
                System.out.println("修改个人资料成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("修改个人资料失败");
        }
    }
}
